package charpter11.lynx;

import java.util.Set;
import java.util.TreeSet;

import net.mindview.util.TextFile;
//看起来这是最糟糕的实现了，你敢跟我比糟糕么
public class Sixteen {
	@SuppressWarnings("rawtypes")
	public static class Vowel implements Comparable{
		private Character character;
		private Integer counter;
		
		public String toString(){
			return "" + character;
		}
		
		public char getChar(){
			return character;
		}
		
		Vowel(char e){
			character = e;
			counter = 1;
		}
		
		public int getCounter(){
			return counter;
		}
		
		public void SetCounter(int counter){
			this.counter = counter;
		}

		@Override
		public int compareTo(Object arg0) {
			if (character - ((Vowel)arg0).getChar() == 0){
				counter += ((Vowel)arg0).getCounter();
				((Vowel)arg0).SetCounter(counter);//不要假设这个比较的是谁，应该同步比较双方的counter
			}
			return character - ((Vowel)arg0).getChar();
		}
	}
	
	public static void main(String[] args){
		Set<Vowel> allVowels = new TreeSet<Vowel>();
		
		Set<String> words = new TreeSet<String>();
		words.addAll(new TextFile("D:\\onTheGoing\\on-the-going\\ThinkingInJava\\tij\\TIJ4-code\\holding\\UniqueWords.java","\\W+"));
		for (String string : words) {
			Set<Vowel> currentVowels = getVowels(string);
			for (Vowel vowel : currentVowels) {
				System.out.println(string + " cotains " + vowel.getCounter() + " " + vowel);
			}
			allVowels.addAll(currentVowels);
		}
		
		for (Vowel vowel : allVowels) {
			System.out.println("All cotains " + vowel.getCounter() + " " + vowel);
		}
	}
	
	private static Set<Vowel> getVowels(String string){
		Set<Vowel> allVowels = new TreeSet<Vowel>();
		for (char c:string.toLowerCase().toCharArray()){
			if (c == 'a'){
				allVowels.add(new Vowel('a'));
			}
			if (c == 'e'){
				allVowels.add(new Vowel('e'));
			}
			if (c == 'i'){
				allVowels.add(new Vowel('i'));
			}
			if (c == 'o'){
				allVowels.add(new Vowel('o'));
			}
			if (c == 'u'){
				allVowels.add(new Vowel('u'));
			}
		}
		return allVowels;
	}
}
